<template>
  <div>
    <card>
      <div style="width:100%;margin-bottom: 5px;">
        <Button type="primary" style="width:100%;" @click="recordClick" ghost>
          <h3>审批进度（点击查看详情）</h3>
        </Button>
        <span>
          <Table :data="approveRecordData" :columns="approveRecordColumns" :show-header="false" size="small" stripe></Table>
        </span>
      </div>
      <div style="width:100%;overflow:hidden;margin-bottom: -10px;">
          <Affix :offset-top="50">
            <div style="display:inline-block;float:left;width:49%;">
                <Button type="primary" @click="backBtn">返回</Button>&nbsp;
            </div>
          </Affix>
      </div>
    </card>
    <div>
      <card>
        <Tabs value="name1" type="card" :animated="true" @on-click="tabOnClick">
          <TabPane label="审核页面" name="name1" :linkOption="{component:'_p/afs-core-business/afs-case/pages/approve/loan-audit/loanAuditDetail',isFull:true,params:{bb:'bb'},pageTitle:'审核页面'}">
            <loan-Audit-Detail ref="loanAuditDetail" :detailParams="detailParams" @getRemarks="getRemarks"></loan-Audit-Detail>
          </TabPane>
          <TabPane label="影像资料" name="name2" style="max-height: 800px;" :linkOption="{component:'projects/basic/pages/image/file-audit/createFileAudit',isFull:true,params:auditParam,pageTitle:this.detailParams.contractNo}">
            <div style="height: calc(100vh - 250px);">
              <fileAudit ref="fileAudit" @getBaseData="getBaseData" @backBtn="backBtn" :auditParam="auditParam" :detailParams="detailParams"></fileAudit>
            </div>
          </TabPane>
          <TabPane label="VIN码解析" name="name3">
            <loan-Audit-Vin ref="loanAuditVin" :detailParams="detailParams"></loan-Audit-Vin>
          </TabPane>
          <TabPane label="见证人查询" name="name4">
            <loan-Audit-witness ref="loanAuditWitness" :detailParams="detailParams"></loan-Audit-witness>
          </TabPane>
        </Tabs>
      </card>
    </div>
  </div>
</template>
<script>
import loanAuditDetail from '@/projects/afs-core-business/pages/case/approve/loan-audit/loanAuditDetail'
import loanAuditVin from '@/projects/afs-core-business/pages/case/approve/loan-audit/loanAuditVin'
import loanAuditWitness from '@/projects/afs-core-business/pages/case/approve/loan-audit/loanAuditWitness'
import fileAudit from '@/projects/basic/pages/image/file-audit/fileAudit'
import {
  getApproveRecord,
  auditSubmit,
} from '_p/afs-core-business/api/afs-case/loan-approve/loanAudit'
export default {
  name: 'loanAuditHistory',
  components: {
    loanAuditDetail,
    loanAuditVin,
    loanAuditWitness,
    fileAudit,
  },
  data() {
    return {
      modalTitle: '',
      saveSubmitData: '',
      baseData:[],
      recordDrop: false,
      approveRecordData:[],
        allRecordData:[],
        callStep:"",
      auditParam: {
        applyStatus: this.detailParams.applyStatus,
        taskId: this.detailParams.taskId,
        busiNo: this.detailParams.contractNo,
        belongNo: this.detailParams.contractNo,
        busiNode: 'loanApply',
      },
      approveRecordColumns: [
        {
          title: '流程节点',
          key: 'disposeNodeName',
          render: (h, params) => {
            return h('span', '流程节点:' + (params.row.disposeNodeName || ''))
          },
        },
        {
          title: '处理人员',
          key: 'disposeStaff',
          render: (h, params) => {
            return h('span', '处理人员:' + (params.row.disposeStaff || ''))
          },
        },
        {
          title: '处理命令',
          key: 'approveSuggestName',
          render: (h, params) => {
            return h(
              'span',
              '处理命令:' + (params.row.approveSuggestName || '')
            )
          },
        },
        {
          title: '处理时间',
          key: 'approveEndTime',
          render: (h, params) => {
            return h('span', '处理时间:' + (params.row.approveEndTime || ''))
          },
        },
        {
          title: '处理意见',
          key: 'approveRemark',
          render: (h, params) => {
            return h('span', '处理意见:' + (params.row.approveRemark || ''))
          },
        },
      ],
    }
  },
  beforeCreate() {
      this.detailParams = this.afs.getPageParams(this);
      console.log(this.detailParams)
  },
  mounted() {
    this.init()
  },
  methods: {
      init(){
          this.refresh()
      },
      getBaseData(val){
        this.baseData = val
      },
    refresh() {
      getApproveRecord(this.detailParams).then((res) => {
        if (res.code === '0000') {
          this.allRecordData = res.data.records;
            this.setApproveRecord(this.recordDrop);
        }
      })
    },
    tabOnClick(name) {
      if (name && name === 'name3') {
        this.$refs.loanAuditVin.summaryBtn()
      }
    },
    getFileList(){
      this.$refs.fileAudit.getFileList();
    },
    backBtn() {
        this.whenClose();
        window.close();
    },
    whenClose(){
        this.afs.afsEmit(this,"flushData");
    },
    recordClick() {
      this.recordDrop = !this.recordDrop
        this.setApproveRecord(this.recordDrop);
    },
      setApproveRecord(val){
        if(!val){
            let records=[];
            this.allRecordData.forEach(function (v){
                if(v.approveSuggest=="backPartners"
                    ||v.approveSuggest=="backAudit"
                    ||v.approveSuggest=="back"
                    ||v.approveSuggest=="sendBack"){
                    records.push(v);
                }
            })
            this.approveRecordData=records;
        }else{
            this.approveRecordData=this.allRecordData;
        }
      },
    getRemarks(val){
        this.detailParams.approveRemark = val;
    },
      // 获取当前时间，day为number，getDay(-1):昨天的日期;getDay(0):今天的日期;getDay(1):明天的日期;【以此类推】
      getDay(day) {
          var today = new Date();
          var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
          today.setTime(targetday_milliseconds); //注意，这行是关键代码

          var tYear = today.getFullYear();
          var tMonth = today.getMonth();
          var tDate = today.getDate();
          tMonth = this.doHandleMonth(tMonth + 1);
          tDate = this.doHandleMonth(tDate);
          return tYear + "-" + tMonth + "-" + tDate;
      },
      p(s) {
          return s < 10 ? '0' + s : s
      },
      doHandleMonth(month) {
          var m = month;
          if (month.toString().length == 1) {
              m = "0" + month;
          }
          return m;
      },
    saveSubmit() {
      auditSubmit(this.detailParams).then((res) => {
        if (res.code === '0000') {
          this.$Message.success('提交成功')
          // this.backToPartnersModalVisible = false
          // this.$emit('backGo')
          this.backBtn();
        }
      })
    },
  },
}
</script>
